@extends('admin.layout.main')
@section("content")
    <form class="layui-form" action="/admin/user/store_password" method="post">
        <div class="layui-form-item"  >
            <div class="layui-input-block"  id="sb" >

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">修改方案</label>
            <div class="layui-input-block">
                <select name="option"   lay-filter="source">
                    <option value="-1" selected="">请选择一项修改方案</option>
                    <option value="0"  >对选中用户进行修改</option>
                    <option value="1" >自行选择更改</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" id="show">
            <div class="layui-inline">
                <label class="layui-form-label">分配用户</label>
                <div class="layui-input-inline">
                    <select name="user_id" >
                        <option value="">请选择用户</option>
                        <optgroup label="员工">
                            @foreach($users as $user)
                                <option value="{{$user->id}}">{{$user->name}}</option>
                            @endforeach
                        </optgroup>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item" id="show1">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password_1" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="show2">
            <label class="layui-form-label">重复新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password_2" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">确认修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>
        layui.use(['form'], function(){
            var form = layui.form;
            var value="";
            form.on('select(source)', function(data) {
                value = data.value; //得到被选中的值
                if (value == -1)
                {
                     $("#show").hide();
                     $("#show1").hide();
                     $("#show2").hide();
                     $("#sb").hide();
                }else if(value ==0){
                    form.render();
                    $("#sb").show();
                    $("#show1").show();
                    $("#show2").show();
                    $("#show").hide();
                }else if(value==1){
                    $("#show").show();
                    $("#show1").show();
                    $("#show2").show();
                    $("#sb").hide();
                }
            });
            //自定义验证规则
            form.verify({
                title: function(value){
                    if(value.length < 5){
                        return '标题至少得5个字符啊';
                    }
                }
                ,pass: [/(.+){5,12}$/, '密码必须5到12位']
            });
        });
    </script>
@endsection